import { Tag } from "antd";
import dayjs from "dayjs";
export const BtnList = {
  "2": "升级",
  "3": "加购",
  "4": "续费",
};
//购买记录
export const calcColumns = (params) => {
  const { operate } = params;
  const columns = [
    {
      title: "订单信息",
      dataIndex: "packageName",
      width: 240,
      render: (_, record) => {
        return (
          <div>
            {record.packageName}
            <br />
            订单号:{record.id}
          </div>
        );
      },
    },
    {
      title: "下单/支付时间",
      dataIndex: "buyTime",
      render: (_, record) => {
        return (
          <div>
            <Tag>下单</Tag>
            {record.buyTime ? dayjs(record.buyTime).format("YYYY-MM-DD") : "-"}
            <br />
            <Tag style={{ marginTop: "10px" }}>支付</Tag>
            {record.payTime ? dayjs(record.payTime).format("YYYY-MM-DD") : "-"}
          </div>
        );
      },
    },
    {
      title: "订单类型",
      dataIndex: "orderType",
      valueEnum: {
        1: { text: "购买套餐" },
        2: { text: "升级套餐" },
        3: { text: "加购场馆" },
        4: { text: "续费" },
        5: { text: "更换套餐" },
      },
    },
    {
      title: "场馆数量",
      dataIndex: "venueNum",
      render: (_, record) => {
        return <span>{record.venueNum}个</span>;
      },
    },
    {
      title: "生效/失效时间",
      dataIndex: "buyTime",
      render: (_, record) => {
        return (
          <div>
            <Tag color="blue">生效</Tag>
            {record.buyTime ? dayjs(record.buyTime).format("YYYY-MM-DD") : "-"}
            <br />
            <Tag style={{ marginTop: "10px" }} color="error">
              失效
            </Tag>
            {record.validityDate
              ? dayjs(record.validityDate).format("YYYY-MM-DD")
              : "-"}
          </div>
        );
      },
    },
    {
      title: "订单状态",
      dataIndex: "orderStatus",
      filters: [
        { text: "待支付", value: "0" },
        { text: "已支付", value: "1" },
        // { text: "部分退款", value: "2" },
        // { text: "已退款", value: "3" },
        { text: "已取消", value: "4" },
        { text: "已失效", value: "5" },
      ],
      onFilter: (value, record) => record.orderStatus.includes(value as string),
      valueEnum: {
        0: { text: "待支付", status: "Processing" },
        1: { text: "已支付", status: "Success" },
        // 2: { text: "部分退款", status: "Default" },
        // 3: { text: "已退款", status: "Default" },
        4: { text: "已取消", status: "Default" },
        5: { text: "已失效", status: "Default" },
      },
    },
    {
      title: "订单金额",
      dataIndex: "orderAmount",
      render: (_, record) => {
        return <span>¥{record.orderAmount / 100}</span>;
      },
      sorter: true,
    },
  ];

  columns.push(operate);
  return columns;
};
//颜色工具转换
export const hexToRgba = (hex, opacity) => {
  return (
    "rgba(" +
    parseInt("0x" + hex.slice(1, 3)) +
    "," +
    parseInt("0x" + hex.slice(3, 5)) +
    "," +
    parseInt("0x" + hex.slice(5, 7)) +
    "," +
    opacity +
    ")"
  );
};
//场馆列表
export const calcColumnsTwo = (params) => {
  const { operate } = params;
  const columns = [
    {
      title: "场馆名称",
      dataIndex: "venueName",
      fieldProps: {
        placeholder: "请输入场馆名称",
      },
      render: (_, record) => {
        return (
          <div>
            {record.venueName}
            {record.isLastVenue == 1 && (
              <Tag style={{ marginLeft: "10px" }} color="processing">
                上次登录
              </Tag>
            )}
          </div>
        );
      },
    },
    {
      title: "联系人",
      dataIndex: "contacts",
      hideInSearch: true,
    },
    {
      title: "联系电话",
      dataIndex: "contactsPhone",
      hideInSearch: true,
    },
    {
      title: "所属区域",
      key: "cascader",
      dataIndex: "cascader",
      width: 100,
      hidden: true,
      fieldProps: {
        options: params.regionList,
        placeholder: "省/市/区",
        fieldNames: {
          label: "name",
          value: "name",
        },
      },
      search: {
        transform: (e) => {
          return e.join("-");
        },
      },
      valueType: "cascader",
    },
    {
      title: "区域",
      dataIndex: "region",
      hideInSearch: true,
      ellipsis: true,
    },
    {
      title: "状态",
      dataIndex: "venueStatus",
      valueType: "radio",
      hideInSearch: true,
      valueEnum: {
        1: { text: "禁用", status: "Error" },
        0: { text: " 启用", status: "Processing" },
      },
    },
  ];

  columns.push(operate);
  return columns;
};
